package com.diorsunion.hedge.client.ui;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.swing.*;
import java.awt.*;

/**
 * Created by harley-dog on 2016/5/23.
 */
@Component("ClientFrame")
public class ClientFrame extends JFrame implements UI {
    @Value("#{application['frame.width']}")
    public int width;
    @Value("#{application['frame.height']}")
    public int height;

    @Resource @Qualifier("infoLogPanel")
    private TextPanel     infoLogPanel;
    @Resource @Qualifier("tradeLogPanel")
    private TextPanel     tradeLogPanel;
    @Resource @Qualifier("errorLogPanel")
    private TextPanel     errorLogPanel;
    @Resource
    ButtonPanel buttonPanel;
    public ClientFrame() {
    }

    @PostConstruct
    public void init(){
        JPanel scrollingWindowDisplayPanel = new JPanel( new GridLayout( 0, 1) );
        scrollingWindowDisplayPanel.add( infoLogPanel);
        scrollingWindowDisplayPanel.add( tradeLogPanel);
        scrollingWindowDisplayPanel.add( errorLogPanel);
        getContentPane().add( scrollingWindowDisplayPanel, BorderLayout.CENTER);
        getContentPane().add(buttonPanel, BorderLayout.WEST);
        super.setTitle("Hedge Client");
        super.setSize(width, height);
        super.setVisible(true);
        super.setResizable(true);
        super.setLocationRelativeTo(null);
        super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    @Bean(name="infoLogPanel")
    public TextPanel getInfoLogPanel(){
        return new TextPanel("程序运行信息", false,Color.BLACK,Color.white,Color.white);
    }
    @Bean(name="tradeLogPanel")
    public TextPanel getTradeLogPanel(){
        return new TextPanel("交易信息", false,Color.BLACK,Color.GREEN,Color.GREEN);
    }
    @Bean(name="errorLogPanel")
    public TextPanel getErrorLogPanel(){
        return new TextPanel("错误信息", false,Color.BLACK,Color.red,Color.red);
    }
}
